package com.wzy.oa_sys.controller.user;

import com.wzy.oa_sys.model.request.user.PasswordReq;
import com.wzy.oa_sys.model.request.user.UserReq;
import com.wzy.oa_sys.model.response.user.UserResp;
import com.wzy.oa_sys.model.response.user.UserRespForTask;
import com.wzy.oa_sys.service.user.UserService;
import com.wzy.oa_sys.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private JwtUtil jwtUtil;

    @RequestMapping("/list")
    public List<UserResp> getUserList() {
        return userService.getUserList();
    }

    @PostMapping("/addUser")
    public void addUser(@RequestBody UserReq userReq) {
        System.out.println("新增用户："+userReq.toString());
        userService.addUser(userReq);
    }

    @GetMapping("/getUserByDeptId/{deptId}")
    public List<UserResp> getUserByDeptId(@PathVariable("deptId") long deptId) {
        System.out.println("根据部门ID查询用户："+deptId);
        return userService.getUserByDeptId(deptId);
    }

    @GetMapping("/getAdminList")
    public List<UserResp> getAdminList() {
        return userService.getAdminList();
    }

    //获取角色为超级管理员和普通管理员的list
    @GetMapping("/getChargeList")
    public List<UserRespForTask> getChargeList() {
        return userService.getChargeList();
    }

    //    获取为正式员工且不为部门负责人的list
    @GetMapping("/getNotDeptManagerList")
    public List<UserResp> getNotDeptManagerList() {
        return userService.getNotDeptManagerList();
    }

    //    获取为部门负责人的list
    @GetMapping("/getDeptManagerList")
    public List<UserResp> getDeptManagerList() {
        return userService.getDeptManagerList();
    }

    @DeleteMapping("/deleteUserById/{id}")
    public void deleteUserById(@PathVariable("id") Integer id) {
        System.out.println("删除用户："+id);
        int i = userService.deleteUserById(id);
        System.out.println("删除结果："+i);
    }

    @GetMapping("/getUserDetialById/{id}")
    public UserResp getUserDetialById(@PathVariable("id") Integer id) {
        System.out.println("查询用户详情："+id);
        return userService.getUserDetialById(id);
    }


    @PutMapping("/updateUserPassword/{id}")
    public void updateUserPassword(@PathVariable("id") long id) {
        userService.updateUserPassword(id);
    }

    @PutMapping("/updateUser")
    public void updateUser(@RequestBody UserReq userReq) {
        userService.updateUser(userReq);
    }

    @PutMapping("/updateUserDetailById")
    public void updateUserDetailById(@RequestBody UserResp userResp) {
        userService.updateMyDetail(userResp);
    }

    @PutMapping("/updatePassword")
    public void updatePassword(@RequestBody PasswordReq passwordReq) {
        userService.updatePassword(passwordReq);
    }

    //获取直线上级
    @GetMapping("/getFather")
    public UserResp getFather(HttpServletRequest request) {
        Long userId = jwtUtil.extractUserId(request);
        return  userService.getFather(userId);
    }
}
